package com.tongji.seller.service
{
	/**
	 * 
	 * @author Assassin
	 * 2011-12-14
	 */
	
	import com.tongji.seller.events.DelStoreSceneEvent;
	import com.tongji.seller.events.GetStoreFavoriteStateEvent;
	import com.tongji.seller.events.GetStoreSavedSceneEvent;
	import com.tongji.seller.events.GetStoreUserSceneEvent;
	import com.tongji.seller.model.StoreSceneModel;
	import com.tongji.seller.model.UserModel;
	
	import flash.system.Security;
	
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.soap.WebService;
	
	import org.robotlegs.mvcs.Actor;
	
	
	public class DelStoreSceneService extends Actor
	{
		private var ws:WebService;
		
		[Inject]
		public var userModel:UserModel;
		
		[Inject]
		public var sceneModel:StoreSceneModel;
		
		public function DelStoreSceneService()
		{
			super();
			ws = new WebService();
			ws.wsdl = "http://share.rryjw.com/VRService.asmx?wsdl";
			ws.useProxy = false;
			ws.loadWSDL();
			Security.loadPolicyFile("http://img.rryjw.com/crossdomain.xml");
		}
		
		/**
		 * 删除店铺用户收藏信息
		 * @param userID
		 * @param sID
		 * 
		 */	
		public function delStoreFavorite(userID:Number, sID:Number):void
		{
			ws.DelStoreFavorite(userID, sID);
			ws.DelStoreFavorite.addEventListener(ResultEvent.RESULT, resultHandler);
			ws.DelStoreFavorite.addEventListener(FaultEvent.FAULT, faultHandler);
		}
		
		/**
		 * 删除店铺搭配的用户场景
		 * @param sID
		 * 
		 */
		public function delStoreUserScene(sID:Number):void
		{
			ws.DelStoreUserScene(sID);
			ws.DelStoreUserScene.addEventListener(ResultEvent.RESULT, deleteUserScenerHandler);
			ws.DelStoreUserScene.addEventListener(FaultEvent.FAULT, faultHandler);
		}
		
		/**
		 * 删除用户保存的系统场景
		 * @param userID
		 * @param sID
		 * 
		 */	
		public function delStoreUserSystemScene(userID:Number, sID:Number):void
		{
			ws.DeleteStoreUserSystemScene(userID, sID);
			ws.DeleteStoreUserSystemScene.addEventListener(ResultEvent.RESULT, deleteStoreSceneHandler);
			ws.DeleteStoreUserSystemScene.addEventListener(FaultEvent.FAULT, faultHandler);
		}
		
		/**
		 * 删除店铺用户保存的宝贝列表
		 * @param userID
		 * @param sID
		 * 
		 */		
		public function delStoreItem(userID:Number, sID:Number):void
		{
			ws.DelStoreItem(userID, sID);
			ws.DelStoreItem.addEventListener(ResultEvent.RESULT, resultHandler);
			ws.DelStoreItem.addEventListener(FaultEvent.FAULT, faultHandler);
		}
		
		private function resultHandler(event:ResultEvent):void
		{
			if (event.result)
			{
				Alert.show("成功移除收藏");
				//dispatch(new GetStoreFavoriteStateEvent(GetStoreFavoriteStateEvent.GET_STORE_FAVORITE_STATE, userModel.currentUserID, 1, 18));
			    sceneModel.removeSuccessResult(userModel.currentUserID);
			}
			else
				Alert.show("移除收藏出错");
		}
		
		private function deleteUserScenerHandler(event:ResultEvent):void
		{
			if (event.result)
			{
				Alert.show("删除成功");
				dispatch(new GetStoreUserSceneEvent(GetStoreUserSceneEvent.GET_STORE_USER_SCENE, userModel.currentUserID, 1, 15));
			}
			else
				Alert.show("删除出错");
		}
		
		private function deleteStoreSceneHandler(event:ResultEvent):void
		{
			if (event.result)
			{
				Alert.show("删除成功");
				dispatch(new GetStoreSavedSceneEvent(GetStoreSavedSceneEvent.GET_SAVED_SCENE, userModel.currentUserID));
				sceneModel.removeSuccessResult(userModel.currentUserID);			
			}
			else
				Alert.show("删除出错");
		}
		
		private function faultHandler(event:FaultEvent):void
		{
			Alert.show("失败" + event.fault.toString());
		}
	}
}